package com.example.nonacademic_education.dao;

import com.example.nonacademic_education.data.request.FileInfoR;
import com.example.nonacademic_education.data.response.FileInfoDto;
import com.example.nonacademic_education.entity.FileInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author xinmiao
 * @description
 * @date 2023/4/18 11:18
 */
public interface FileDao {
    Integer addBatch(String pre, List<FileInfo> files, String s, Long applyId, Long departmentId, Long projectId, Integer isNecessary, Integer year,Long uploaderId);

    List<String> getPathsByIds(@Param("ids") List<Long> ids,Integer pos);

    @Select("select * from file where id=#{id}")
    FileInfo getOneById(Long id);

    @Update("update file set audit_status=0,name=#{filename},url=#{url} where id=#{id}")
    Integer updateAuditStatusTo0(Long id, String filename, String url);

    @Update("update file set audit_status=2,cause='' where id=#{fileId}")
    Integer pass(Long fileId);
    @Update("update file set audit_status=1,cause=#{cause} where id=#{fileId}")
    Integer noPass(Long fileId, String cause);
    @Select("select count(id) from file where apply_id=#{applyId} and audit_status!=2")
    Integer getNoPassByApplyId(Long applyId);

    List<FileInfoDto> multiConditionQuery(@Param("fi") FileInfoR fileInfoR, Integer page, Integer size);

    Integer countMultiConditionQuery(@Param("fi") FileInfoR fileInfoR);

    Integer deleteByIds(@Param("ids") List<Long> ids);

    @Select("select count(id) from file where apply_id=#{applyId}")
    Integer countByApplyId(Long applyId);

    @Update("update file set source_id=id where apply_id=#{applyId}")
    Integer setSourceId(Long applyId);

    Integer addReUploadFile(Long id, String originalFilename, String url,@Param("file") FileInfo fileInfo);

    @Select("select max(version) from file where source_id=#{id}")
    Integer getMaxVersionBySourceId(Long id);
}
